package com.jic.member.impl;

import com.alibaba.fastjson.JSON;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.member.entity.MememberIntegralLog;
import com.jic.member.mapper.MememberIntegralLogMapper;
import com.jic.member.service.MememberIntegralLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员积分流水表
 * @author : 
 * @email : 
 * @since : 2020-04-17 12:50:47
 * @version : v1.0.0
 */
@Slf4j
@Service
public class MememberIntegralLogServiceImpl implements MememberIntegralLogService {

    @Autowired
    private MememberIntegralLogMapper mememberIntegralLogMapper;

    @Override
    public long insert(MememberIntegralLog mememberIntegralLog) {
        long flag = mememberIntegralLogMapper.insert(mememberIntegralLog);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return mememberIntegralLogMapper.delete(id);
    }

    @Override
    public long update(MememberIntegralLog mememberIntegralLog) {
        return mememberIntegralLogMapper.update(mememberIntegralLog);
    }

    @Override
    public MememberIntegralLog queryByPrimaryKey(Long id){
        return mememberIntegralLogMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MememberIntegralLog> query(MememberIntegralLog mememberIntegralLog){
        return mememberIntegralLogMapper.query(mememberIntegralLog);
    }

    /**
     * 查询当前会员积分流水列表
     * @param mememberIntegralLog
     * @param pageQuery
     * @return
     */
    @Override
    public PageResult<MememberIntegralLog> queryPage(MememberIntegralLog mememberIntegralLog, Page pageQuery) {
        log.info("开始查询当前会员积分流水列表==》入参,{}",mememberIntegralLog,pageQuery);
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MememberIntegralLog> list = mememberIntegralLogMapper.queryPage(startIndex, pageQuery.getLimit(), mememberIntegralLog);
        log.info("结束查询当前会员积分流水列表==》结果,{}",list);
        log.info("开始查询当前会员积分流水列表总数==》入参,{}",mememberIntegralLog);
        long count = mememberIntegralLogMapper.queryPageCount(mememberIntegralLog);
        log.info("结束查询当前会员积分流水列表总数==》结果,{}",count);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        log.info("查询当前会员积分流水列表返回==》,{}", JSON.toJSONString(pageResult));
        return pageResult;
    }
}